package com.wanmait.baohan.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


import com.wanmait.baohan.mapper.BookingHotelApplicationMapper;
import com.wanmait.baohan.mapper.HotelAccountMapper;
import com.wanmait.baohan.mapper.HotelApprovalMapper;
import com.wanmait.baohan.pojo.BookingHotelApplication;
import com.wanmait.baohan.pojo.HotelAccount;
import com.wanmait.baohan.pojo.HotelApproval;
import com.wanmait.baohan.pojo.Staff;

import com.wanmait.baohan.service.BookingHotelService;
import com.wanmait.baohan.util.CreatJobNumberUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * TODO
 *
 * @author hxn
 * @version 1.0
 * @date 2020/12/15 18:03
 * @description: 派车申请service
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BookingHotelServiceImpl implements BookingHotelService {

    @Resource
    HttpServletRequest request;

    @Resource
    BookingHotelApplicationMapper bookingHotelApplicationMapper;

    @Resource
    private HotelAccountMapper hotelAccountMapper;

    @Resource
    HotelApprovalMapper hotelApprovalMapper;

    /**
     * hxn
     * @param object
     * 提交预订酒店申请
     */
    @Override
    public void insert(BookingHotelApplication object) {
        object.setAddTime(new Date());
        object.setState(1);
        object.setNumbering("hotel" + CreatJobNumberUtil.creatJobNumber((Integer)request.getServletContext().getAttribute("hotelApplicationNumbering")));
        bookingHotelApplicationMapper.insert(object);
    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public void update(BookingHotelApplication object) {

    }

    @Override
    public BookingHotelApplication findById(Integer id) {
        return bookingHotelApplicationMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<BookingHotelApplication> findAll() {
        return null;
    }

    @Override
    public List<BookingHotelApplication> findAll(BookingHotelApplication object) {
        return null;
    }

    @Override
    public PageInfo<BookingHotelApplication> findPage(int pageNum) {
        return null;
    }

    @Override
    public PageInfo<BookingHotelApplication> findPage() {
        return null;
    }

    @Override
    public PageInfo<BookingHotelApplication> findPage(int pageNum, BookingHotelApplication object) {
        return null;
    }

    @Override
    public PageInfo<BookingHotelApplication> findPage(BookingHotelApplication object) {
        return null;
    }


    @Override
    public PageInfo<BookingHotelApplication> selectMyHotelApplications(Integer page, Integer limit, BookingHotelApplication bookingHotelApplication) {
        PageHelper.startPage(page, limit);
        List<BookingHotelApplication> bookingHotelApplications = bookingHotelApplicationMapper.selectByStaffid(bookingHotelApplication);
        PageInfo<BookingHotelApplication> pageInfo = new PageInfo<>(bookingHotelApplications, 7);
        return pageInfo;
    }

    @Override
    public void updateByHotel(Integer userId,Integer trvalId) {
        bookingHotelApplicationMapper.updateByHotel(userId,trvalId);
    }

    @Override
    public BookingHotelApplication selectByReId(Integer id) {
        return bookingHotelApplicationMapper.selectByReId(id);
    }

    //查看台账
    @Override
    public List<HotelAccount> findBookingListById(Integer id) {
      List<HotelAccount> list= hotelAccountMapper.findBookingListById(id);
        return list;
    }

    /**
     * hxn
     * @param page
     * @param limit
     * @return
     * 获取全部
     */
    @Override
    public PageInfo<BookingHotelApplication> findAllWithPageAndLimit(Integer page, Integer limit, BookingHotelApplication bookingHotelApplication) {
        PageHelper.startPage(page, limit);
        List<BookingHotelApplication> bookingHotelApplications = bookingHotelApplicationMapper.selectAll(bookingHotelApplication);
        PageInfo<BookingHotelApplication> pageInfo = new PageInfo<>(bookingHotelApplications, 7);
        return pageInfo;
    }

    @Override
    public void submitApprove(HotelApproval hotelApproval) {
        Staff user = (Staff)request.getSession().getAttribute("user");
        hotelApproval.setStaff(user);
        hotelApproval.setApprovalTime(new Date());
        hotelApprovalMapper.insert(hotelApproval);
        bookingHotelApplicationMapper.updateState(hotelApproval.getBookingHotelApplicationId(), hotelApproval.getState());
    }

    @Override
    public BookingHotelApplication findByHotel(BookingHotelApplication bookingHotelApplication) {
        return bookingHotelApplicationMapper.selectByHotel(bookingHotelApplication);
    }
}
